home *** CD-ROM | disk | FTP | other *** search
/ The Atari Compendium / The Atari Compendium (Toad Computers) (1994).iso / files / prgtools / editors / mutt / me2s_pl7.zoo / mu_edit2 / util / char.h < prev    next >
Encoding:
C/C++ Source or Header  |  1993-07-05  |  3.0 KB  |  96 lines

  1. /* $Id: char.h,v 1.1 1992/09/06 19:31:32 mike Exp $ */
  2.  
  3. /* $Log: char.h,v $
  4.  * Revision 1.1  1992/09/06  19:31:32  mike
  5.  * Initial revision
  6.  *
  7.  */
  8.  
  9. /*
  10.  * char.h:  a replacement ctype.h
  11.  * C Durland    Public Domain
  12.  */
  13.  
  14. /*
  15.  * isalnum(c)    non-zero if c is alpha or digit
  16.  * isalpha(c)    non-zero if c is alpha
  17.  * isascii(c)    non-zero if c is ASCII
  18.  * iscntrl(c)    non-zero if c is control character
  19.  * isdigit(c)    non-zero if c is a digit (0 to 9)
  20.  * islower(c)    non-zero if c is lower case
  21.  * ispunct(c)    non-zero if c is punctuation
  22.  * isspace(c)    non-zero if c is white space
  23.  * isupper(c)    non-zero if c is upper case
  24.  
  25.  * isprint(c)    non-zero if c is printable (including blank)
  26.  * isgraph(c)    non-zero if c is graphic (excluding blank)
  27.   
  28.  * _toupper(c)    jam c to uppercase no matter what
  29.  * TOUPPER(c)    convert c to uppercase if it is lowercase
  30.  * _tolower(c)    jam c to lowercase no matter what
  31.  * TOLOWER(c)    convert c to lowercase if it is uppercase
  32.  */
  33.  
  34. #ifndef __CHAR_H_INCLUDED
  35. #define __CHAR_H_INCLUDED
  36.  
  37. #define    _W    0x01    /* Word */
  38. #define    _U    0x02    /* Upper case letter */
  39. #define    _L    0x04    /* Lower case letter */
  40. #define    _C    0x08    /* Control */
  41. #define _N    0x10    /* number */
  42. #define _S    0x20    /* space */
  43. #define _P    0x40    /* punctuation */
  44.  
  45. extern unsigned char _cinfo[];    /* in char.c */
  46.  
  47. #define isalnum(c)    (_cinfo[(unsigned char)(c)] & (_U|_L|_N))
  48. #define isalpha(c)    (_cinfo[(unsigned char)(c)] & (_U|_L))
  49. #define    iscntrl(c)    (_cinfo[(unsigned char)(c)] & _C)
  50. #define isdigit(c)    (_cinfo[(unsigned char)(c)] & _N)
  51. #define    islower(c)    (_cinfo[(unsigned char)(c)] & _L)
  52. #define ispunct(c)    (_cinfo[(unsigned char)(c)] & _P)
  53. #define isspace(c)    (_cinfo[(unsigned char)(c)] & _S)
  54. #define    isupper(c)    (_cinfo[(unsigned char)(c)] & _U)
  55. #define    isword(c)    (_cinfo[(unsigned char)(c)] & _W)
  56.  
  57. #define isgraph(c)    (_cinfo[(unsigned char)(c)] & (_U|_L|_N|_P))
  58. #define isprint(c)    (_cinfo[(unsigned char)(c)] & (_U|_L|_N|_P|_S))
  59.  
  60. #define toascii(c)    ((unsigned char)(c) & 0x7F)
  61.  
  62. #define add_cinfo(c,x)    _cinfo[(unsigned char)(c)] |= x
  63. #define remove_cinfo(c,x) _cinfo[(unsigned char)(c)] &= ~(x)
  64.  
  65. #ifndef CHAR_MAPS
  66.  
  67.     /* Note:  these only really work with ASCII ie < 0x7F */
  68. #define    _toupper(c)    ((unsigned char)(c) & 0xDF)
  69. #define    TOUPPER(c)    (islower(c) ? _toupper(c) : (c))
  70. #define    _tolower(c)    ((unsigned char)(c) | ' ')
  71. #define    TOLOWER(c)    (isupper(c) ? _tolower(c) : (c))
  72.  
  73. #else
  74.  
  75. extern unsigned char _lcmap[], _ucmap[];
  76.  
  77. #define    _toupper(c)    _ucmap[(unsigned char)(c)]
  78. #define    TOUPPER(c)    _ucmap[(unsigned char)(c)]
  79. #define    _tolower(c)    _lcmap[(unsigned char)(c)]
  80. #define    TOLOWER(c)    _lcmap[(unsigned char)(c)]
  81.  
  82. #define set_toupper(a,A) _ucmap[(unsigned char)(a)] = (A)
  83. #define set_tolower(A,a) _lcmap[(unsigned char)(A)] = (a)
  84.  
  85. #endif
  86.  
  87.     /* Case insensitive table stuff.
  88.      * Define _cmap[256] in your code and munge it.
  89.      */
  90. extern unsigned char _cmap[];
  91.  
  92. #define ceq(c1,c2)        /* character compare */\
  93.     (_cmap[(unsigned char)(c1)] == _cmap[(unsigned char)(c2)])
  94.  
  95. #endif    /* __CHAR_H_INCLUDED */
  96.